//
//  MBSpaceZhuBoCell.m
//  MiBaoTu
//
//  Created by admin on 16/9/27.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceZhuBoCell.h"

@interface MBSpaceZhuBoCell () {
    UIView              *_bgView;
    UIImageView         *_userImgView;
    UILabel             *_nickNameLb;
    UILabel             *_contentLb;
    UIImageView         *_rightImgView;
    UIView              *_lineView;
}

@end
@implementation MBSpaceZhuBoCell

- (void)awakeFromNib {
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self onCreateUI];
    }
    return self;
}

- (void)onCreateUI
{
    self.backgroundColor = [UIColor clearColor];
    self.backgroundView = nil;
    
    //背景
    _bgView = [[UIView alloc]initWithFrame:CGRectZero];
    _bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_bgView];

    //头像
    _userImgView = [[UIImageView alloc]initWithFrame:CGRectZero];
    _userImgView.backgroundColor = [UIColor clearColor];
    [_bgView addSubview:_userImgView];
    
    //昵称
    _nickNameLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _nickNameLb.backgroundColor = [UIColor clearColor];
    _nickNameLb.textAlignment = NSTextAlignmentLeft;
    _nickNameLb.textColor = UIColorFromHex(0x333333);
    _nickNameLb.font = [UIFont systemFontOfSize:13.f];
    [_bgView addSubview:_nickNameLb];
    
    //内容
    _contentLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _contentLb.backgroundColor = [UIColor clearColor];
    _contentLb.textAlignment = NSTextAlignmentLeft;
    _contentLb.textColor = UIColorFromHex(0x999999);
    _contentLb.font = [UIFont systemFontOfSize:13.f];
    [_bgView addSubview:_contentLb];
    
    //线
    _lineView = [[UIView alloc]initWithFrame:CGRectZero];
    _lineView.backgroundColor = [UIColorFromHex(0x999999) colorWithAlphaComponent:.15];
    [_bgView addSubview:_lineView];

    _rightImgView = [[UIImageView alloc]initWithFrame:CGRectZero];
    _rightImgView.backgroundColor = [UIColor clearColor];
    [_bgView addSubview:_rightImgView];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setOrientation:(UIDeviceOrientation)orientation
{
    _orientation = orientation;
    [self setNeedsLayout];
}

- (void)setAnchorDic:(NSDictionary *)anchorDic
{
    _anchorDic = anchorDic;
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //value
    if (_anchorDic) {
        NSString *face = [_anchorDic objectForKey:@"FaceImg"];
        if (![face isKindOfClass:[NSNull class]]) {
            [_userImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,[_anchorDic objectForKey:@"FaceImg"]]] placeholderImage:[UIImage imageNamed:@"story_header_bg"]];
        } else {
            _userImgView.image = [UIImage imageNamed:@"story_header_bg"];
        }
        _nickNameLb.text = [NSString stringWithFormat:@"%@",[_anchorDic objectForKey:@"NickName"]];
        _contentLb.text = [NSString stringWithFormat:@"%@个粉丝",[_anchorDic objectForKey:@"FansNum"]];
    }
    UIImage *rightImg = [UIImage imageNamed:@"arrow"];
    _rightImgView.image = rightImg;
    
    
    //frame
    _bgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 110*PERCEN);
    
    _userImgView.frame = CGRectMake((ISIPAD?460*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), (_bgView.height-80*PERCEN)/2., 80*PERCEN, 80*PERCEN);

    _nickNameLb.frame = CGRectMake(_userImgView.right+20*PERCEN, _userImgView.top, 200, 20);
    
    _contentLb.frame = CGRectMake(_nickNameLb.left, (WIDTH_5S ? _nickNameLb.bottom -2: _bgView.height-_nickNameLb.height-20*PERCEN), _nickNameLb.width, _nickNameLb.height);
    
    _lineView.frame = CGRectMake((ISIPAD?440*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0), _bgView.height-1, _bgView.width-(ISIPAD?880*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0), 1);
    
    _rightImgView.frame = CGRectMake(_bgView.width-(ISIPAD?440*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN)-rightImg.size.width, (_bgView.height-rightImg.size.height)/2., rightImg.size.width, rightImg.size.height);
}

@end
